<?PHP
$PageID=6;
include_once('../../core/common.php');
?>


<!DOCTYPE html>
<html lang="zh-cn">
  <head>
    <meta charset="utf-8" />
    <title>管理-页面-页面总览</title>
  </head>
  
	<body>
	
  <table id="data" lay-filter="datatable"></table>
  
		<script type="text/html" id="urlbottom">
			<a href="{{d.PageUrl}}"  target="_blank" rel="noopener" >{{d.PageUrl}}</a>
		</script>

 
<script type="text/html" id="toolbar">
  <div class="layui-btn-container">
    <button class="layui-btn layui-btn-fluid layui-btn-sm" lay-event="add">添加</button>
  </div>
</script>

  
		<script type="text/html" id="rightbar">
			<div class="layui-btn-group">
				<a class="layui-btn layui-btn-sm layui-btn-fluid" lay-event="edit">编辑</a>
				<a class="layui-btn layui-btn-danger layui-btn-sm layui-btn-fluid" lay-event="del">删除</a>
			</div>
		</script> 


		<script>
		layui.use(['table', 'layer', 'dropdown'], function(){
			var table = layui.table;
			var dropdown = layui.dropdown;
			var $ = layui.$;
			
			table.render({
			elem: '#data'
			,height: 521
			,url: './data/' //数据接口
			,toolbar: '#toolbar'
			,page: true //开启分页
			,cols: [[ //表头
			{field: 'PageID', title: '页面ID', width:100, sort: true, fixed: 'left'}
			,{field: 'PageName', title: '页面名称', width:300}
			,{field: 'PageUrl', title: '页面Url(相对根目录)(点击可跳转)', templet: '#urlbottom', width:600}
			,{fixed: 'right', title:'操作', width: 300, minWidth: 200, toolbar: '#rightbar'}
				]]
			});
  
  
  
  table.on('toolbar(datatable)', function(obj){
    var id = obj.config.id;
    var checkStatus = table.checkStatus(id);
    switch(obj.event){
      case 'add':
        var data = checkStatus.data;
		
		layer.open({
        title: '添加新页面',
        type: 2, 
		area: ['80%','25%'],
        content: './add/?AuthSystem=1'
      });
		
      break;
    };
  });
  
  
  
  
  
  
  table.on('tool(datatable)', function(obj){ // 双击 toolDouble
    var data = obj.data;
    //console.log(obj);
    if(obj.event === 'del'){
      layer.confirm('确定删除页面:“'+data.PageName+'”么', function(index){
		  
	$.ajax({
          url: './del/',
          type: 'get',
          data: {
             PageID:data.PageID
          },
          dataType: 'JSON',
          success: function (data) {

                       if (data.code == '0') {
                           obj.del();
                           layer.close(index);
                           layer.msg(data.msg, {icon: 1, time: 1000, shade: 0.1});
                           //reload();
                       } else {
                          layer.close(index);
                          layer.alert(data.msg, {
                               icon: 2, title: '错误提示'
                           });
                           return;
                       }
                   },
            error: function () { }


        })
		
		  
        //obj.del();
       //layer.close(index);
      });
    } else if(obj.event === 'edit'){
      layer.open({
        title: '编辑',
        type: 2,
        area: ['80%','30%'],
        content: './edit/?PageID='+data.PageID+'&PageName='+data.PageName+'&PageUrl='+data.PageUrl+'&AuthSystem=1'
      });
    }
	
	
  });
  
		});
		
		
	
  
  
  
		</script>
		
		
 
 

  

	</body>
</html>
